package cc.facesign.admin.listener;

import cc.facesign.admin.bean.EmailBean;
import cc.facesign.admin.service.MailService;
import cc.facesign.admin.utils.MqUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = {MqUtils.EMAIL_ROUTER_QUEUE})
@Slf4j
public class EmailMqListener {

    @Autowired
    private MailService mailService;

    @RabbitHandler
    public void sendMail(EmailBean emailBean) {
        for (String e : emailBean.getAddressees()) {
            try {
                mailService.sendHtmlMail(e, emailBean.getTitle(), emailBean.getDescription());
            } catch (Exception exception) {

            }
        }
    }
}
